import hashes
import optparse
import backend
import common
import os
import sys

AVAILABLE_HASHES = [x for x in dir(hashes) if ("_" not in x) and (x not in ("Crypto", "hashmodule", "name"))]
AVAILABLE_CHARSETS = [x.replace("_CHARSET", "").lower() for x in dir(backend) if x.endswith("_CHARSET")]

PRESET_FILE_PATH = None
for variable in ("HOME", "home", "USERPROFILE"):
	if os.environ.has_key(variable):
		PRESET_FILE_PATH = os.path.join(os.environ[variable], "presets.mkp")
		break
if PRESET_FILE_PATH is None:
	raise common.PYMKException("Unable to determine user home path")

def get_parser():
    parser = optparse.OptionParser()
    parser.add_option("-m", "--modifier", dest="modifier", default="", help="Modifier string", metavar="MODIFIER")
    parser.add_option("-a", "--age", dest="age", default=1, type="int", help="Password age")
    parser.add_option("-l", "--length", dest="length", default=10, type="int", help="Password length")

    ############ CHARSETS
    parser.add_option("-c", "--charset", dest="charset", default="normal", help="Character set. Possibilities: %s. Default: %%default" % ", ".join(AVAILABLE_CHARSETS)) 
    #####################
    
    parser.add_option("-H", "--hash", dest="hash_name", default="sha256", help="hash name (%s)" % (", ".join(AVAILABLE_HASHES)))
    parser.add_option("-f", "--preset-file", dest="preset_file", default=PRESET_FILE_PATH, help="preset filename (default = %default)")
    parser.add_option("-p", "--preset", dest="preset_name", metavar="PRESET", default=None, help="name of the preset to load")
    parser.add_option("-v", "--verbose", dest="verbose", action="store_true", default=False)
    parser.add_option("-x", "--no-copy", dest="no_copy", action="store_true", default=False, help="Do not copy to the clipboard (only display password)")
    parser.add_option("-w", "--wipe-timeout", dest="wipe_timeout", type="int", default=10, help="number of seconds after which the clipboard will be emptied.")
    parser.add_option("--version", dest="version_only", action = "store_true", default=False, help="print version number and exit.")
    parser.add_option("-s", "--save", dest="save", action="store_true", default=False, help="save preset")
    parser.add_option("-M", "--merge", dest="merge", metavar="OTHER_PRESET_FILE", default=None, help="merge another preset file to the current preset file")
    parser.add_option("-L", "--list-presets", dest="list_presets", action="store_true", default=False)
    return parser
    
